package com.bnz.manager.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.bnz.common.entity.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bnz.manager.entity.BrandEntity;
import com.bnz.manager.service.BrandService;
import com.bnz.common.utils.PageUtils;




/**
 * 品牌
 *
 * @author Haziy
 * @email 1143878025@qq.com
 * @date 2023-02-16 14:12:33
 */
@RestController
@RequestMapping("/manager/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;


    @GetMapping("/findAll")
    public R findAll(){
        List<Map<String,String>> brandList = brandService.list().stream().map(m -> {
            Map<String,String> map = new HashMap<>();
            map.put("id", m.getId());
            map.put("text", m.getName());
            return map;
        }).collect(Collectors.toList());

        return R.ok().put("brandList", brandList);
    }
    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {

        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		BrandEntity brand = brandService.getById(id);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody BrandEntity brand){
		brandService.save(brand);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody BrandEntity brand){
		brandService.updateById(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] ids){
		brandService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
